var ie  = document.all
var ns6 = document.getElementById && !document.all

var isMenu  = false ;
var menuSelObj = null ;
var overpopupmenu = false;
var menuObj = null
var callbackId = null;
var className_backup = null;

var isDoubleClick = false;
var posX = null;
var posY = null;

function popupmeu_close ( event ) {
	// hidde popupmenu and reset all data
	if( isMenu && overpopupmenu == false ){
		isMenu = false ;
		menuObj.style.display = "none";
		menuObj = null;

		// return callback id
		id = callbackId;
		callbackId = null;

		document.getElementById( id ).className = className_backup;
		className_backup = null;

		return id;
	}
	//return false;
}

// POP UP MENU
function popupmeu_open ( event ) {
	if( this.id.lastIndexOf("__") > 0 )
		popupId = "popupmenu__" + this.id.slice(this.id.lastIndexOf("__") + 2);
	else popupId = "popupmenu__" + this.id;

	// close popupmenu if one other is open
	if( menuObj && menuObj.id != popupId ){
		overpopupmenu = false;
		popupmeu_close(event);
	}

	if( !document.getElementById(popupId) )
		return;

	if( callbackId && this.id != callbackId )
		return;

  	menuSelObj = ns6 ? event.target.parentNode : window.event.srcElement.parentElement;
  	menuObj = document.getElementById(popupId);

  	// browserweiche
	if (ns6){
		// menu position
  		posX = event.clientX + window.pageXOffset;
  		posY = event.clientY + window.pageYOffset;
	}
	else{
		// menu position
  		posX = window.event.clientX + document.documentElement.scrollLeft;
  		posY = window.event.clientY + document.documentElement.scrollTop;
	}

	window.setTimeout("popupmeu_open_display()", 300);
	if( this.className != "popupmenu__is__open" ){
	  	className_backup = this.className;
		this.className = "popupmenu__is__open";
	}

  	isMenu = true;
	overpopupmenu = true;
	callbackId = this.id;
	return callbackId;
}

function popupmeu_open_display(){
	if( isDoubleClick )
		return;

	menuObj.style.display = "block";

	// browserweiche
	if (ns6){
		// menu position
		windoxX = window.innerWidth;
		windoxY = window.innerHeight;

		if( posX + menuObj.offsetWidth > windoxX ) menuObj.style.left = posX - menuObj.offsetWidth + "px";
		else menuObj.style.left = posX + "px";

		if( posY + menuObj.offsetHeight > windoxY ) menuObj.style.top = posY - menuObj.offsetHeight + "px";
		else menuObj.style.top = posY + "px";
	}
	else{
		// menu position
		windoxX = document.body.clientWidth;
		windoxY = document.body.clientHeight;

		if( posX + menuObj.offsetWidth > windoxX ) menuObj.style.pixelLeft = posX - menuObj.offsetWidth;
		else menuObj.style.pixelLeft = posX;

		if( posY + menuObj.offsetHeight > windoxY ) menuObj.style.pixelTop = posY - menuObj.offsetHeight;
		else menuObj.style.pixelTop = posY;
	}

	isDoubleClick = false;
}